﻿namespace ServerTest
{
    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using ServerApp;
    using Server;

    public class Clear
    {
        public static void ClearBase()
        {
            InternetShopBaseEntities entity = ServerApp.SingleEntity.GetInstance();

            if (entity.ProductItems.Count() > 0)
                foreach (var item in entity.ProductItems)
                {
                    entity.DeleteObject(item);
                }

            if (entity.OrderProducts.Count() > 0)
                foreach (var item in entity.OrderProducts)
                {
                    entity.DeleteObject(item);
                }
            if (entity.Orders.Count() > 0)
                foreach (var item in entity.Orders)
                {
                    entity.DeleteObject(item);
                }
            if (entity.Customers.Count() > 0)
                foreach (var item in entity.Customers)
                {
                    entity.DeleteObject(item);
                }

            if (entity.PlaceLocalizations.Count() > 0)
                foreach (var item in entity.PlaceLocalizations)
                {
                    entity.DeleteObject(item);
                }
            if (entity.Places.Count() > 0)
                foreach (var item in entity.Places)
                {
                    entity.DeleteObject(item);
                }

            if (entity.ExternalOrderProductProducers.Count() > 0)
                foreach (var item in entity.ExternalOrderProductProducers)
                {
                    entity.DeleteObject(item);
                }
            if (entity.ExternalOrders.Count() > 0)
                foreach (var item in entity.ExternalOrders)
                {
                    entity.DeleteObject(item);
                }

            if (entity.ProductProducers.Count() > 0)
                foreach (var item in entity.ProductProducers)
                {
                    entity.DeleteObject(item);
                }
            if (entity.Producers.Count() > 0)
                foreach (var item in entity.Producers)
                {
                    entity.DeleteObject(item);
                }

            if (entity.ProductLocalizations.Count() > 0)
                foreach (var item in entity.ProductLocalizations)
                {
                    entity.DeleteObject(item);
                }
            if (entity.ProductGalleries.Count() > 0)
                foreach (var item in entity.ProductGalleries)
                {
                    entity.DeleteObject(item);
                }
            if (entity.Products.Count() > 0)
                foreach (var item in entity.Products)
                {
                    entity.DeleteObject(item);
                }

            if (entity.ProductCategoryLocalizations.Count() > 0)
                foreach (var item in entity.ProductCategoryLocalizations)
                {
                    entity.DeleteObject(item);
                }
            if (entity.ProductCategories.Count() > 0)
                foreach (var item in entity.ProductCategories)
                {
                    entity.DeleteObject(item);
                }

            entity.SaveChanges();
        }
    }
}
